package RefactoringA1.src;

/**
 * Completed.
 * @author christopher.witcher
 *
 */
public class DebitCard 
{
	private static int fLastDebitCardNumber;
	private CheckingAccount fAccountConnectedTo;
	private int fDebitCardNumber;
	
	/**
	 * These fields below are not used in any way in this 
	 * class and should use the Customer Data Class to store  this
	 * information.
	 * 
	#Refactored created field customer
	
	private String fName;
	private String fStreet;
	private String fTown;
	private String fZipCode;
	private String fCountry;*/
	
	private CustomerData customer = null;
	
	/**
	 *  #Refactored.
	 *  
	 *  These Constructors should be assigning Customer 
	 *  information to the a variable customer of the CustomerData 
	 *  class.
	 *   
	 * @param name
	 * @param street
	 * @param town
	 * @param zipCode
	 * @param country
	 */
	public DebitCard(String name, String street, String town, String zipCode, String country)
	{
		fDebitCardNumber = fLastDebitCardNumber;
		customer = new CustomerData(name, street, zipCode, town,country, fDebitCardNumber);
		
		fLastDebitCardNumber++;
	}
	
	/**
	 * #Refactored
	 * All these parameters were pushed into the CustomerData class.
	 * 
	 * @param name
	 * @param street
	 * @param town
	 * @param zipCode
	 * @param country
	 * @param limit
	 * @param account
	 */
	public DebitCard(CustomerData the_customer, double limit, CheckingAccount account)
	{
		fDebitCardNumber = fLastDebitCardNumber;
		customer = new CustomerData(the_customer.getfName(), the_customer.getfStreet(), 
				the_customer.getfZipCode(), the_customer.getfTown(),the_customer.getfCountry(),
				fDebitCardNumber);
		fLastDebitCardNumber++;
		fAccountConnectedTo = account;
	}
	
	/**
	 * This method has multiple return statements and should be refactored.
	 * 
	 * #Refactored
	 * @param amount
	 * @return
	 */
	public boolean pay(double amount)
	{
		boolean output = false;
		if((fAccountConnectedTo.getBalance() - amount) < -fAccountConnectedTo.getDebitAmount())
		{
			fAccountConnectedTo.setBalance(fAccountConnectedTo.getBalance() - amount);
			output = true;
		}
		
		return output;
	}
	
	/**
	 * #Refactored
	 * 
	 * There was no way to get the customer information.  Creation of a 
	 * getter method was necessary.
	 * @return
	 */
	public CustomerData getCustomer()
	{
		return this.customer;
	}

}
